package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.InOrderBean;
import com.project.bean.OutOrderBean;
import com.project.mapper.IInOrderMapper;
import com.project.mapper.IOutDetailMapper;
import com.project.mapper.IOutOrderMapper;
import com.project.service.IOutOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class OutOrderServiceImpl  implements IOutOrderService {
    @Autowired
    private IOutOrderMapper orderMapper;
    @Autowired
    private IOutDetailMapper outDetailMapper;
    @Override
    public IPage<OutOrderBean> cutByItem(Integer pageNO, String name, LocalDate startDate, LocalDate endDate) {
        QueryWrapper<OutOrderBean> qw =new QueryWrapper<>();
        if (name !=null && name.length()!=0){
            qw.like("oo_name",name);
        }
        if (startDate !=null){
            qw.ge("oo_date",startDate);
        }
        if (endDate!=null ){
            qw.le("oo_date",endDate);
        }

        return orderMapper.selectPage(new Page<>(pageNO,3),qw) ;
    }

    @Override
    public OutOrderBean findById(Integer orderId) {

        OutOrderBean orderBean = orderMapper.selectById(orderId);
        orderBean.setOutDetailBeanList(outDetailMapper.findByOrderId(orderId));
        return orderBean;

    }
}
